package xaj.scc.ast;

import polyglot.ast.Node;
import polyglot.ext.jl.ast.Node_c;
import polyglot.util.CodeWriter;
import polyglot.util.Position;
import polyglot.visit.NodeVisitor;
import polyglot.visit.PrettyPrinter;

public class OrFactor_c extends Node_c implements OrFactor {

	private Factor left, right;
	
	public OrFactor_c(Position pos, Factor left, Factor right) {
		super(pos);
		this.left = left;
		this.right = right;
	}

	public Factor getLeftSide() {
		return left;
	}

	public Factor getRightSide() {
		return right;
	}

	public OrFactor setLeftSide(Factor f) {
		OrFactor_c n = (OrFactor_c) copy();
		n.left = f;
		return n;
	}

	public OrFactor setRightSide(Factor f) {
		OrFactor_c n = (OrFactor_c) copy();
		n.right = f;
		return n;
	}

	protected OrFactor_c reconstruct(Factor l, Factor r) {
		if(this.left != l || this.right != r) {
			OrFactor_c n = (OrFactor_c) copy();
			n.left = l;
			n.right = r;
			return n;
		}
		return this;
	}
	
	public Node visitChildren(NodeVisitor v) {
		Factor left = (Factor) this.left.visit(v);
		Factor right = (Factor) this.right.visit(v);
		return reconstruct(left, right);
	}
	
	public void prettyPrint(CodeWriter w, PrettyPrinter tr) {
		w.write("(");
		left.prettyPrint(w, tr);
		w.write(" | ");
		right.prettyPrint(w, tr);
		w.write(")");
	}

	@Override
	public void accept(Visitor v) {
		v.visitOrFactor(this);
		
	}
	
}
